//
//  LSSecondCommentCell.m
//  LookScore
//
//  Created by wws on 2018/3/29.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSSecondCommentCell.h"
#import "ConversationIssueModel.h"
#import "UITableViewCell+HYBMasonryAutoCellHeight.h"
@implementation LSSecondCommentCell{
    
    UILabel * _nickNameLabel;
    UILabel * _commentLabel;
    UIButton * _praiseButton;
    UILabel * _timeLabel;
    
}

+ (LSSecondCommentCell *)LSSecondCommentCellCellWidthTableView:(UITableView *)tableView{
    LSSecondCommentCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSSecondCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    
    return self;
    
}

- (void)addContentView{
    
    UIView * view = [[UIView alloc] init];
    view.backgroundColor = LSBackGroundColor;
    self.backgroundView = view;
    
    
    
    _nickNameLabel = [[UILabel alloc] init];
    _nickNameLabel.textColor = LSTitleGrayColor3;
    _nickNameLabel.font = LSFontSize14;
   
    
    _commentLabel = [[UILabel alloc] init];
    _commentLabel.textColor = LSTitleGrayColor3;
    _commentLabel.numberOfLines = 0;
    _commentLabel.font = LSFontSize14;
    
    //点赞按钮
    _praiseButton=[UIButton new];
    [_praiseButton setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_praiseButton setImage:[UIImage imageNamed:@"ChatPraise"] forState:UIControlStateNormal];
    _praiseButton.titleLabel.font=LSFontSize10;
    [_praiseButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
//    [_praiseButton addTarget:self action:@selector(praiseButtonSender:) forControlEvents:UIControlEventTouchUpInside];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = LSFontSize9;
    _timeLabel.textColor = LSTitleGrayColor3;
    
    
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = LSLineGrayColor;
    
    [self.contentView sd_addSubviews:@[_nickNameLabel,_commentLabel,_praiseButton,_timeLabel,lineView]];
     
     _nickNameLabel.sd_layout.leftEqualToView(self.contentView).offset(10).topSpaceToView(self.contentView, 5).autoHeightRatio(0);
        [_nickNameLabel setSingleLineAutoResizeWithMaxWidth:180];
    _praiseButton.sd_layout.rightEqualToView(self.contentView).offset(-5).centerYEqualToView(_nickNameLabel).heightIs(20).widthIs(50);
    
    _commentLabel.sd_layout.leftEqualToView(_nickNameLabel).rightEqualToView(_praiseButton).autoHeightRatio(0).topSpaceToView(_nickNameLabel, 5);
    _timeLabel.sd_layout.leftEqualToView(_nickNameLabel).topSpaceToView(_commentLabel, 5).autoHeightRatio(0);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:180];

    lineView.sd_layout.leftEqualToView(self.contentView).rightEqualToView(self.contentView).topSpaceToView(_timeLabel, 9).heightIs(1);
    
    [self setupAutoHeightWithBottomView:_timeLabel bottomMargin:10];
    
    self.hyb_lastViewInCell = lineView;
    self.hyb_bottomOffsetToCell = 0.0;//cell底部距离为3.0个间隙
    
}
- (void)setFirstModel:(CommentIssueModel *)firstModel{
    
    _firstModel = firstModel;
    
    
}
- (void)setModel:(LSSecondCommentModel *)model{
    
    _model = model;
    if (_firstModel.Id == model.BeCommentId) {
        _nickNameLabel.text = model.UserDisName;
    }else{
        
        _nickNameLabel.text = [NSString stringWithFormat:@"%@回复%@",model.UserDisName,model.BeUserName];
    }
    
    _commentLabel.text = model.MainContent;
    _timeLabel.text = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    [_praiseButton setTitle:[NSString stringWithFormat:@"%ld",model.ThumbupCount] forState:UIControlStateNormal];
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
